package com.example.briandang;

import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;


public class MainActivity extends ActionBarActivity {

	public final static String EXTRA_MESSAGE = "com.example.briandang.MESSAGE";
	
	void openSearch()
	{
		System.out.println("openSearch()");
		
	}
	
	void openSettings()
	{
		System.out.println("openSettings()");
	}
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    /* Add Actions to the Action Bar
     * 
     * To place menu items into the action bar, implement this function.
     * Get MenuInflater
     * Inflate() R.menu.main into Menu menu
     * return super.onCreateOptionsMenu(menu);
     * */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.main, menu);
        return super.onCreateOptionsMenu(menu);
    }

    /* Respond to Action Buttons
     * 
     * When the user presses an action button or an item in action overflow, 
     * this callback method is called.
     * Call getItemId() on the given MenuItem to determine which item was pressed.
     * The returned Id is the value declared in the <item> element's android:id attribute.
     * */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        
        if(id == R.id.action_search) {
        	openSearch();
        	return true;
        }
        else if (id == R.id.action_settings) {
            openSettings();
        	return true;
        }
        
        return super.onOptionsItemSelected(item);
    }
    
    /* Called when the user clicks the button 
     * In order for the system to match this method with the method name
     * in android:onClick, the signature must be exactly the same.
     * 
     * The following are required:
     * 		- must be public
     * 		- must have a void return value
     * 		- have a View as the only parameter (the View that was clicked)
     * */
    public void sendMessage(View view)
    {
    	// Do something in response to the button
    	
    	// An intent is created to start an activity called DisplayMessageActivity
    	// Intent constructor takes a Context as a first parameter.  
    	// 		A Context is a base class of Activity class
    	// 2nd Parameter: The Class of the app component to which the system 
    	// 		should deliver the Intent
    	// An intent not only allows you to start another activity but it can
    	//		carry data to the activity as well. Using findViewById()
    	//		allows this function to get the EditText element
    	Intent intent = new Intent(this, DisplayMessageActivity.class);
    	EditText editText = (EditText) findViewById(R.id.edit_message);
    	String message = editText.getText().toString();
    	
    	// An Intent can carry a collection of various data types as key-value pairs
    	// 		called extras. The putExtra() method takes the key name and the value.
    	// In order for the next activity to query the extra data, you should define 
    	//		the key for your intent's extra using a public constant. So add
    	// 		the EXTRA_MESSAGE definition to the top of the MainActivity class.
    	// Generally, it's good practice to define keys for intent extras using
    	//		your app's package name as a prefix. This guarantees that they are
    	//		unique.
    	intent.putExtra(EXTRA_MESSAGE, message);
    	
    	// To start an activity, call startActivity and pass the Intent.
    	// The system starts an instance of the Activity specified by the Intent
    	startActivity(intent);
    }
    
    public void startStyleActionBarActivity(View view)
    {
    	Intent intent = new Intent(this, StyleActionBarActivity.class);
    	startActivity(intent);
    }
    
    public void startBgImgActivity(View view){
    	Intent intent = new Intent(this, BackgroundImageActivity.class);
    	startActivity(intent);
    }
    
    public void startGoActivity(View view){
    	Intent intent = new Intent(this, GoActivity.class);
    	startActivity(intent);
    }
    
    public void startPlayVideoActivity(View view){
    	Intent intent = new Intent(this, VideoActivity.class);
    	startActivity(intent);
    }
    
    public void startScalingActivity(View view)
    {
        Intent intent = new Intent(this, ScalingActivity.class);
        startActivity(intent);
    }
}
